<?php
namespace Fiestissima\CRM\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Doctrine\ORM\EntityRepository;

class DiarioProductoType extends AbstractType
{
	
	public function buildForm(FormBuilderInterface $builder, array $options)
	{
		$builder
		->add('dDescuento', 'percent')
		->add('dUnidades', 'choice', array('choices' => array('1'=>'1', 
															  '2'=>'2', 
															  '3'=>'3', 
															  '4'=>'4', 
															  '5'=>'5', 
															  '6'=>'6', 
															  '7'=>'7', 
															  '8'=>'8', 
															  '9'=>'9', 
															  '10'=>'10', 
															  '11'=>'11', 
															  '12'=>'12', 
															  '13'=>'13', 
															  '14'=>'14', 
															  '15'=>'15')))
		->add('dSubtotal', 'text')
		->add('diario', 'entity', array('class' => 'FiestissimaCRM:Diario',
				'query_builder' => function(EntityRepository $er) {
					return $er->createQueryBuilder('d')
					->where('d.d_fecha = CURRENT_DATE()');
				}))
		->add('formaPago', 'entity', array('class' => 'FiestissimaCRM:FormaPago',
				'query_builder' => function(EntityRepository $er) {
					return $er->createQueryBuilder('fp');
				}))
		->add('producto', 'entity', array('class' => 'FiestissimaCRM:Producto',
				'query_builder' => function(EntityRepository $er) {
					return $er->createQueryBuilder('p')
					->orderBy('p.pr_nombre', 'ASC');
				}, 'expanded' => false, 'multiple' => false));
	}
	
	public function getName()
	{
		return 'diarioProducto';
	}
	
	public function setDefaultOptions(OptionsResolverInterface $resolver)
	{
		$resolver->setDefaults(array(
				'data_class' => 'Fiestissima\CRM\Entity\DiarioProducto',
		));
	}
}